class InitialSetup < ActiveRecord::Migration
  def self.up
     create_table(:users,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
      t.string :user_name,:null=>false,:limit=>50
      t.string :nick_name,:limit=>50
      t.string :real_name,:limit=>50
      t.string :crypted_password,:null=>false
      t.string :salt
      t.string :email
      t.string :signature
      t.string :blog_url
      t.string :site_url
      t.string :user_pic
      t.string :city,:limit=>50
      t.string :self_intro
      t.integer :points,:limit=>3,:default=>0
      t.integer :fans_total,:limit=>2,:default=>0
      t.integer :friend_total,:limit=>2,:default=>0
      t.string :rember_token
      t.datetime :rember_token_expires_at
      t.datetime :last_login_time
      t.string :ip,:limit=>20
      t.integer :flag,:limit=>1
      t.integer :status,:limit=>1,:default=>0
      t.timestamps                 
     end
     
     create_table(:user_favorite_subjects,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
       t.integer :user_id
       t.string :title,:null=>false       
       t.string :description,:limit=>500
       t.integer :status,:default=>0,:limit=>1,:null=>false
       t.integer :flag,:limit=>1
       t.text :remarks
       t.timestamps
     end
     
     create_table(:user_favorite_infos,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
       t.integer :user_id
       t.integer :subject_id,:null=>false
       t.integer :item_id,:null=>false
       t.string :item_name
       t.string :item_pic
       t.integer :status,:default=>0,:limit=>1,:null=>false
       t.timestamps
     end
     
     create_table(:messages,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
       t.integer :send_user_id,:null=>false
       t.integer :receive_user_id,:null=>false
       t.string :title,:limit=>100
       t.string :content,:limit=>2000,:null=>false
       t.integer :flag,:limit=>1
       t.integer :status,:limit=>1,:default=>0,:null=>false
       t.timestamps
     end
      
      create_table(:friends,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :user_id
        t.integer :friend_user_id,:null=>false
        t.integer :status,:limit=>1,:default=>0,:null=>false
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:user_verifies,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :user_id
        t.string :verify_code
      end
      
      create_table(:items,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :name,:null=>false
        t.string :description,:limit=>500      
        t.integer :want_buy_count,:limit=>3
        t.integer :bought_count,:limit=>3
        t.integer :cat1_id
        t.string :cat1_name
        t.integer :cat2_id
        t.string :cat2_name
        t.string :main_pic
        t.string :tags
        t.integer :style_id
        t.string :style_name
        t.integer :brand_id
        t.string :brand_name
        t.string :cloth_type
        t.string :season,:limit=>20
        t.string :pic_design
        t.float :total_rating,:limit=>1
        t.float :impression_rating,:limit=>1
        t.float :quality_rating,:limit=>1
        t.float :comfort_rating,:limit=>1
        t.integer :first_comment_user_id,:default=>-1
        t.integer :status,:limit=>1,:default=>0,:null=>false
        t.integer :flag,:limit=>1
        t.text :remarks
        t.string :meta_keywrods
        t.string :meta_description
        t.timestamps
      end 
      create_table(:item_categories,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :parent_id
        t.string :name,:null=>false
        t.integer :cat_level,:limit=>1
        t.integer :is_parent,:limit=>1
        t.integer :sort_order,:limit=>2
        t.integer :status,:limit=>1,:default=>0,:null=>false
        t.string :permalink
        t.string :meta_keywords
        t.string :meta_description
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:item_alliances,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :link
        t.float :price,:limit=>2
        t.string :name
        t.integer :user_id
        t.integer :status,:limit=>1,:default=>0
        t.string :shop_name,:default=>nil
        t.decimal :commission_rate,:precision=>2,:scale=>2
        t.datetime :list_time
        t.datetime :delist_time
        t.datetime :check_time
        t.integer :flag,:limit=>1
        t.text :remark
        t.timestamps
      end
      create_table(:item_pictures,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_id,:null=>false
        t.integer :user_id
        t.string :pic_1
        t.string :pic_2
        t.string :pic_3
        t.integer :status,:limit=>1,:default=>0
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:picture_comments,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :picture_id,:null=>false
        t.string :content,:limit=>1000,:null=>false
        t.integer :user_id
        t.integer :status,:limit=>1,:default=>0
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:item_ratings,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :user_id
        t.integer :item_id,:null=>false
        t.string :item_title
        t.string :title
        t.text :content,:null=>false,:limit=>2000
        t.string :tags
        t.integer :reply_count,:limit=>2,:default=>0
        t.integer :total_rating,:limit=>1
        t.integer :impression_rating,:limit=>1
        t.integer :quality_rating,:limit=>1
        t.integer :comfort_rating,:limit=>1
        t.integer :status,:limit=>1,:default=>0
        t.integer :total_count,:limit=>2
        t.integer :flag,:limit=>1
        t.string :ip,:limit=>20
        t.timestamps
      end
      create_table(:item_rating_replies,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :user_id
        t.integer :item_comment_id,:null=>false
        t.string :content,:limit=>1000,:null=>false
        t.integer :status,:limit=>1,:default=>0
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:brands,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :name
        t.text :description
        t.string :url
        t.string :logo
        t.integer :status,:limit=>1,:default=>0
        t.text :remark
        t.integer :flag,:limit=>1
        t.string :meta_keywords
        t.string :meta_description
        t.timestamps
      end
      create_table(:tags,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :name,:null=>false
        t.string :description,:limit=>500
        t.integer :status,:limit=>1,:default=>0
        t.text :remark
        t.integer :flag,:limit=>1
        t.timestamps
      end
      create_table(:item_tags,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_id,:null=>false
        t.integer :tag_id,:null=>false
        t.string :name
        t.integer :total_num,:limit=>3,:default=>0
        t.integer :status, :limit=>1,:default=>0
        t.timestamps
      end
      create_table(:item_styles,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :name,:null=>false
        t.text :description
        t.integer :status,:limit=>1,:default=>0
        t.string :remark
        t.integer :flag,:limit=>1
        t.string :meta_keywords
        t.string :meta_description
        t.timestamps
      end
      create_table(:item_rating_voles,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_comment_id,:null=>false
        t.integer :down,:limit=>2,:default=>0
        t.integer :up,:limit=>2,:default=>0
        t.integer :stauts,:limit=>1,:default=>0
        t.timestamps
      end
      
      create_table(:item_statistics,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_id,:null=>false
        t.string :item_name
        t.integer :item_alliance_id
        t.string :buy_link
        t.integer :click_count,:limit=>4
        t.timestamps
      end
      
      create_table(:item_recommends,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_id,:null=>false
        t.string :item_name
        t.string :item_pic
        t.integer :position,:limit=>1
        t.integer :remd_type,:limit=>1
        t.integer :status,:limit=>1,:default=>0
        t.timestamps
        
      end
      
      create_table(:item_promotions,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :item_id
        t.string :item_name
        t.text :intro,:limit=>2000
        t.integer :sort_order,:limit=>2
        t.integer :status,:limit=>1,:default=>0
        t.timestamps
      end
      
      create_table(:sys_alliances,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.integer :user_id
        t.string :user_name
        t.string :real_name
        t.string :email
        t.string :ali_account
        t.string :qq
        t.string :site_url
        t.text :remarks
        t.integer :status,:limit=>1,:default=>0
        t.integer :flag,:limit=>1
        t.timestamps
        
      end
      
      create_table(:sys_user_spiders,:options=>'ENGINE=InnoDB DEFAULT CHARSET=utf8',:force => true) do |t|
        t.string :name
        t.string :shop_url
        t.string :detail_url
        t.string :shop_url_md5
        t.string :detail_url_md5
        t.string :email
        t.integer :status,:limit=>1,:default=>0
        t.timestamps
        
      end
      
                       
  end

  def self.down
    drop_table :users
    drop_table :user_favorite_subjects
    drop_table :user_favorite_infos
    drop_table :messages
    drop_table :friends
    drop_table :user_verifies
    drop_table :item_categories
    drop_table :item_pictures
    drop_table :item_alliances
    drop_table :picture_comments
    drop_table :item_ratings
    drop_table :item_rating_replies
    drop_table :brands
    drop_table :tags
    drop_table :items
    drop_table :item_tags
    drop_table :item_styles
    drop_table :item_rating_voles
    drop_table :item_statistics
    drop_table :item_recommends
    drop_table :item_promotions
    drop_table :sys_alliances
    drop_table :sys_user_spiders
    #drop_table :sys_tag_lines
  end
end
